package com.zx.erp.purchase.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zx.erp.purchase.bean.CBrand;
import com.zx.erp.purchase.mapper.CBrandMapper;
import com.zx.erp.purchase.service.CBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zx.erp.sys.bean.Module;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 作者信息
 * @since 2021-11-10
 */
@Service
public class CBrandServiceImpl extends ServiceImpl<CBrandMapper, CBrand> implements CBrandService {

    @Autowired
    private CBrandMapper mapper;

    @Override
    public Page<CBrand> getBrandListByCondition(CBrand cBrand, Integer pageNo, Integer pageSize) {
        Page<CBrand> page = new Page<CBrand>(pageNo,pageSize);
        Page<CBrand> pageInfo = mapper.getBrandListByCondition(page, cBrand);
        return pageInfo;
    }

    @Override
    public CBrand getOneBrandByCondition(Integer brandId) {
        return mapper.getOneBrandByCondition(brandId);
    }

    @Transactional
    @Override
    public boolean brandAdd(CBrand brand) {
        return mapper.brandAdd(brand);
    }

    @Transactional
    @Override
    public boolean brandUpdate(CBrand brand) {
        return mapper.brandUpdate(brand);
    }
    @Override
    public PageInfo<CBrand> findAll(CBrand cBrand, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<CBrand> cBrands = mapper.selectAll(cBrand);
        PageInfo<CBrand> pageInfo=new PageInfo<CBrand>(cBrands);
        return pageInfo;
    }
}
